Public Class frmClientes
    Dim MiGestDatos As GestDatos
    Dim MiCursorRaton As New GestProyecto

    Private Sub frmClientes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MiCursorRaton.CursorRaton(True)

        Dim Ruta As String
        Ruta = "Data Source =" & System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) & "\DBGestion.sdf;"
        Dim LineaSQL(0) As String
        Dim Tabla(0) As String
        LineaSQL(0) = "Select CodCliente,Cliente From Clientes"
        Tabla(0) = "Clientes"

        MiGestDatos = New GestDatos
        MiGestDatos.ConextarBD(Ruta, LineaSQL, Tabla)
        cboFClientes.Text = "NINGUN FILTRO"

        MiCursorRaton.CursorRaton(False)


    End Sub

    Private Sub cboFClientes_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFClientes.TextChanged

        MiCursorRaton.CursorRaton(True)

        If cboFClientes.Text = "NINGUN FILTRO" Then
            txtFClientes.Enabled = False
            btnFClientes.Enabled = False
            MostrarDatosGrid("")
            txtFClientes.Text = ""
        Else
            txtFClientes.Enabled = True
            btnFClientes.Enabled = True
        End If

        If Not cboFClientes.Text = "NINGUN FILTRO" Then
            txtFClientes.Focus()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub


    Sub MostrarDatosGrid(ByVal Condicion As String)

        Condicion = Condicion


        Dim grdEmcabezados As New GestDatos.Emcabezados

        grdEmcabezados.add(New GestDatos.Emcabezado("CodCliente", "CODIGO", 60))
        grdEmcabezados.add(New GestDatos.Emcabezado("Cliente", "CLIENTE", 154))

        MiGestDatos.DatosGrid(grdClientes, grdEmcabezados, "Clientes", Condicion)

    End Sub

    Private Sub btnFClientes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFClientes.Click

        MiCursorRaton.CursorRaton(True)

        If Not txtFClientes.Text = "" Then
            Dim MiCondicion As String

            If cboFClientes.Text = "NOMBRE" Then
                MiCondicion = "Cliente Like '" & CStr(txtFClientes.Text) & "%'"
            Else
                MiCondicion = "CodCliente Like '" & CStr(txtFClientes.Text) & "%'"
            End If

            MostrarDatosGrid(MiCondicion)

        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub grdClientes_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdClientes.DoubleClick

        MiCursorRaton.CursorRaton(True)

        If lblFormulario.Text = "Pedidos" Then
            With frmInicio.MifrmPedido
                .txtCodCli.Text = grdClientes.Item(grdClientes.CurrentRowIndex, 0).ToString
                .lblCliente.Text = grdClientes.Item(grdClientes.CurrentRowIndex, 1).ToString
                .txtCodCli.Focus()
            End With
            Me.Dispose()
        Else
            frmInicio.MifrmDClientes = New frmDClientes
            frmInicio.MifrmDClientes.txtCod.Text = grdClientes.Item(grdClientes.CurrentRowIndex, 0).ToString
            frmInicio.MifrmDClientes.Show()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub mnuSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSalir.Click
        Me.Dispose()
    End Sub
    Private Sub grdClientes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdClientes.Click

        MiCursorRaton.CursorRaton(True)

        grdClientes.Select(grdClientes.CurrentRowIndex)

        MiCursorRaton.CursorRaton(True)

    End Sub

End Class